<template>
	<div style="color: gray;text-align: left;">
		上传课程详情
	</div>
    <el-row class="row1">
	<el-col :span="5" style="margin-left: 600px;">
	</el-col>
	<el-col :span="4">
		<div style="color: gray;text-align: left;">
			{{this.className}}
		</div>
	
	</el-col>
	
	</el-row>
  <el-table
  class="table"
    :data="tableData"
    stripe
	ref = "multipleTable"
	@selection-change="selectL"
    style="width: 100%;margin-top: 25px;"
	:header-cell-style="{background:'#199ED8',color:'white'}">
	
	<el-table-column type="selection"></el-table-column>
	
    <el-table-column
      prop="course_code"
      label="课程编号"
      >
    </el-table-column>
	
    <el-table-column
      prop="course_name"
      label="课程名称">
    </el-table-column>
	
	<el-table-column
	 prop="course_class"
	 label="课程类别">
	</el-table-column>
	
	<el-table-column
	  prop="credit"
	  label="课程学分">
	</el-table-column>
	
  </el-table>
  
  <el-button style="background-color: green; color: white; margin-top: 10px;" @click="selected">
  	认证
  </el-button>
</template>

<script>
// import { kebabCase } from 'element-plus/es/utils'
import axios from "axios"

import { toRaw } from "@vue/reactivity";
  export default {
    data() {
      return {
        tableData: [],
		classId: 0,
		className: '',
		listSelect: [],
		idList:[]
      }
    },
	created() {
	    // 获取路由参数
	    this.classId = this.$route.query.classId;
	  },
	mounted() {
		const that = this
		const url = this.$API_URL + '/teacher/getClassName';
		axios.get(url, {
				params: {
					class_id: that.classId
				}
			}, {
				headers: {
					'Content-Type': 'application/json'
				}
			})
			.then(response => {
				that.className = response.data;
			})
			const url2 = this.$API_URL + '/teacher/getAllCourse';
			axios.get(url2,{
					headers: {
						'Content-Type': 'application/json'
					}
				})
				.then(response => {
					that.tableData = response.data;
				})
	},

	
 methods:{
selectL (val) {
  this.listSelect = val;
},
selected(){
	const that=this;
	var arr=[];
	for(let i of that.listSelect){
		arr.push(i.course_id)
	}
	that.idList = arr
	console.log(that.idList)
	const url3 = this.$API_URL + '/teacher/access';
	var formData=new FormData();
	formData.append('user_id',1);
	formData.append('class_id',that.classId);
	formData.append('courseList',that.idList)
	axios.post(url3,formData,{
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	})
	     .then((res) => {return res})
	     .catch((err) => {return err})
 }
 }
  }
</script>

<style lang="scss">
	.controls {
		display: flex;
		flex-direction: row;
	    margin-left: 900px;
		padding: 20rpx 30rpx;
	
		.date-container {
			width: 80%;
		}
	}
</style>